#include "XStormPublisher.h"

namespace Xts
{
	namespace IceRuntime
	{
		XStormPublisher::XStormPublisher(const Ice::CommunicatorPtr& pIc, const Ice::LoggerPtr& pLogger)
			:XStormBase(pIc, pLogger)
		{
		}

		XStormPublisher::~XStormPublisher(void)
		{
		}

		bool XStormPublisher::RetrievePublishPrx(const ::std::string& topicName, ::Ice::ObjectPrx& publisherPrx)
		{
			/*if(!IsTopicManagerValid())
			{
				x_pLogger->error("Topic Manager is not initialized. Can't retrieve publisher Proxy.");
				return false;
			}

			if(x_pIc->isShutdown())
			{
				x_pLogger->error("Shutdown is already called on Ice.Communicator. Can't retrieve publisher Proxy.");
				return false;
			}*/

			::IceStorm::TopicPrx topic = RetrieveTopic(topicName);
			if(topic == NULL)
			{
				x_pLogger->error("Failed to retrieve topic:" + topicName);
				return false;
			}

			try
			{
				publisherPrx = topic->getPublisher();
				return true;
			}			
			catch (const ::Ice::Exception& ex)
			{
				x_pLogger->error(ex.what());
			}
			return false;
		}
	}
}

